/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.oracleandsxnd.erp.xsd.web;

import com.oracleandsxnd.erp.common.persistence.Page;
import com.oracleandsxnd.erp.common.persistence.TableSplitResult;
import com.oracleandsxnd.erp.common.utils.StringUtils;
import com.oracleandsxnd.erp.common.web.AjaxResult;
import com.oracleandsxnd.erp.common.web.BaseController;
import com.oracleandsxnd.erp.seting.entity.Company;
import com.oracleandsxnd.erp.seting.entity.Logistics;
import com.oracleandsxnd.erp.seting.service.CompanyService;
import com.oracleandsxnd.erp.seting.service.LogisticsService;
import com.oracleandsxnd.erp.xsd.entity.XsglSaleChange;
import com.oracleandsxnd.erp.xsd.entity.XsglSaleType;
import com.oracleandsxnd.erp.xsd.service.XsglSaleChangeService;
import com.oracleandsxnd.erp.xsd.service.XsglSaleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 换货单Controller
 * @author 换货单
 * @version 2019-12-21
 */
@Controller
@RequestMapping(value = "xsd_xsglSaleChange")
public class XsglSaleChangeController extends BaseController {

	@Autowired
	private XsglSaleChangeService xsglSaleChangeService;

	@RequestMapping(value = {""})
	public String list(Model model) {

		return "erp/xsd/xsglSaleChangeList";
	}
	@RequestMapping(value = {"listData"})
	@ResponseBody
	public Object listData(XsglSaleChange xsglSaleChange , HttpServletRequest request, HttpServletResponse response){
		Page<XsglSaleChange> page = xsglSaleChangeService.findPage(new Page<XsglSaleChange>(request, response), xsglSaleChange);
		TableSplitResult<XsglSaleChange> result=new TableSplitResult<XsglSaleChange>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}

	@Autowired
	private XsglSaleTypeService xsglSaleTypeService;
	@Autowired
	private CompanyService companyService;

	@Autowired
	private LogisticsService logisticsService;
	@RequestMapping(value = "form")
	public String form(String id, Model model) {
		XsglSaleChange xsglSaleChange=null;
		if (StringUtils.isNotBlank(id)){
			xsglSaleChange = xsglSaleChangeService.get(id);
		}
		if (xsglSaleChange == null){
			xsglSaleChange = new XsglSaleChange();
		}
		Company c=new Company();
		c.setType("1");
		model.addAttribute("logistics",logisticsService.findList(new Logistics()));
		model.addAttribute("companys",companyService.findList(c));
		model.addAttribute("kinds",xsglSaleTypeService.findList(new XsglSaleType()));
		model.addAttribute("xsglSaleChange",xsglSaleChange);
		return "erp/xsd/xsglSaleChangeForm";
	}


	@RequestMapping(value = "save")
	public String save(XsglSaleChange xsglSaleChange) {

		xsglSaleChangeService.save(xsglSaleChange);
		return "redirect:/xsd_xsglSaleChange/form";

	}

	@RequestMapping(value = "delete")
	@ResponseBody
	public AjaxResult delete(XsglSaleChange xsglSaleChange, RedirectAttributes redirectAttributes) {
		xsglSaleChangeService.delete(xsglSaleChange);
		return success();
	}


}